package com.maila.xiaoaoschool.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.maila.xiaoaoschool.R;
import com.zhy.autolayout.AutoRelativeLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 意见反馈
 * Created by Administrator on 2017/10/18.
 */

public class FeedbackActivity extends AppCompatActivity {
    @BindView(R.id.white_return_iv)
    AutoRelativeLayout whiteReturnIv;
    @BindView(R.id.et_content)
    EditText etContent;
    @BindView(R.id.tv_hint)
    TextView tvHint;
    @BindView(R.id.btn_commit)
    TextView btnCommit;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feedback);
        ButterKnife.bind(this);
        etContent.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                if(editable!=null&&etContent.getText().length()>0&&etContent.getText().length()<=50){
                    tvHint.setText(etContent.getText().length()+"/50");
                    tvHint.setTextColor(Color.parseColor("#ababab"));
                }else if(editable!=null&&etContent.getText().length()>50){
                    tvHint.setText(etContent.getText().length()+"/50");
                    tvHint.setTextColor(Color.RED);
                    Toast.makeText(FeedbackActivity.this, "已超出字数限制", Toast.LENGTH_SHORT).show();
                }else {
                    tvHint.setText("0/50");
                    tvHint.setTextColor(Color.parseColor("#ababab"));
                }
            }
        });
    }

    @OnClick({R.id.white_return_iv, R.id.btn_commit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.white_return_iv:
                finish();
                break;
            case R.id.btn_commit:
                break;
        }
    }
}
